class StationsController < ApplicationController
  def index
    @stations = Station.order("ciudad").all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @stations }
    end
  end

  def new
    @station = Station.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @stations }
    end
  end

  def create
    @station = Station.new(params[:station])

    if @station.save
			respond_to do |format|
		    format.html { redirect_to(stations_path, :notice => "La terminal #{@station.ciudad} se creo correctamente.") }
		    format.xml  { render :xml => @station, :status => :created, :location => @station }
			end
    else
			respond_to do |format|
		    format.html { render :action => "new" }
		    format.xml  { render :xml => @station.errors, :status => :unprocessable_entity }
		  end
    end
  end

  def edit
    @station = Station.find(params[:id])
  end

	def update
    @station = Station.find(params[:id])

    if @station.update_attributes(params[:station])
	    respond_to do |format|
	      format.html { redirect_to(stations_path, :notice => 'Station was successfully updated.') }
	      format.xml  { head :ok }
			end
    else
	    respond_to do |format|
		    format.html { render :action => "edit" }
		    format.xml  { render :xml => @station.errors, :status => :unprocessable_entity }
	    end
    end
  end

  def destroy
    @station = Station.find(params[:id])
    @station.destroy

    respond_to do |format|
      format.html { redirect_to(stations_url) }
      format.xml  { head :ok }
    end
  end
end
